#ifndef SSHSESSION_H
#define SSHSESSION_H

#include <libssh/libssh.h>
#include <string>
#include <QDebug>

#include "sshchannel.h"
#include "QLibSsh_global.h"

class QLIBSSH_EXPORT SshSession final : public SharePtr<ssh_session>
{
public:
    SshSession(const std::string& user, const std::string& host, const int port, std::string password);
    SshSession();

    ~SshSession() override;

    inline void setHost(const char* host) const {
        ssh_options_set(mPtr, SSH_OPTIONS_HOST, host);
    }

    inline void setPort(int port) const {
        ssh_options_set(mPtr, SSH_OPTIONS_PORT, &port);
    }

    inline void setPort(const char* port) const {
        ssh_options_set(mPtr, SSH_OPTIONS_PORT_STR, port);
    }

    inline void setUser(const char* user) const {
        ssh_options_set(mPtr, SSH_OPTIONS_USER, user);
    }

    [[nodiscard]] inline bool isConnected() const {
        return ssh_is_connected(mPtr);
    }

    [[nodiscard]] bool connect() const;

    inline void disconnect() const {
        ssh_disconnect(mPtr);
    }

    [[nodiscard]] inline SshChannel CreateChannel() const {
        return SshChannel(ssh_channel_new(mPtr));
    }

    inline const  char* GetError() const{
        return ssh_get_error(mPtr);
    }
private:
    std::string mPassword {};
};

#endif // SSHSESSION_H
